package com.ruicar.afs.cloud.afscase.approvetask.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruicar.afs.cloud.afscase.approvetask.condition.WaitTaskPoolCondition;
import com.ruicar.afs.cloud.afscase.approvetask.condition.WorkTaskPoolCondition;
import com.ruicar.afs.cloud.afscase.approvetask.entity.WorkTaskPool;
import com.ruicar.afs.cloud.afscase.approvetask.mapper.WorkTaskPoolMapper;
import com.ruicar.afs.cloud.afscase.approvetask.service.WorkTaskPoolService;
import com.ruicar.afs.cloud.afscase.approvetask.vo.ApproveTaskVo;
import com.ruicar.afs.cloud.afscase.approvetask.vo.CaseBaseInfoVo;
import com.ruicar.afs.cloud.afscase.approvetask.vo.NoOperateTaskVo;
import com.ruicar.afs.cloud.afscase.approvetask.vo.WaitTaskVO;
import com.ruicar.afs.cloud.afscase.infomanagement.entity.CaseBaseInfo;
import com.ruicar.afs.cloud.afscase.infomanagement.entity.CaseContractInfo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>Description: </p>
 *
 * @author ZC.GUO
 * @version 1.0
 * @date create on 2020-05-17 10:41
 */
@Service
@AllArgsConstructor
@Data
@Slf4j
public class WorkTaskPoolServiceImpl extends ServiceImpl<WorkTaskPoolMapper, WorkTaskPool> implements WorkTaskPoolService {

    WorkTaskPoolMapper workTaskPoolMapper;

    @Override
    public IPage<WaitTaskVO> getAllWaitTaskList(Page page, WaitTaskPoolCondition waitTaskPoolCondition) {
        return baseMapper.getAllWaitTaskList(page, waitTaskPoolCondition);
    }

    @Override
    public IPage<ApproveTaskVo> queryCommonPoolTaskList(Page page, WorkTaskPoolCondition workTaskPoolCondition) {
        return baseMapper.queryCommonPoolTaskList(page, workTaskPoolCondition);
    }

    @Override
    public IPage<ApproveTaskVo> queryApproveTaskList(Page page, WorkTaskPoolCondition workTaskPoolCondition) {
        return baseMapper.queryApproveTaskList(page, workTaskPoolCondition);
    }

    @Override
    public IPage<ApproveTaskVo> queryGroupLeaderTaskList(Page page, WorkTaskPoolCondition workTaskPoolCondition) {
        return baseMapper.queryGroupLeaderTaskList(page, workTaskPoolCondition);
    }

    @Override
    public IPage<CaseBaseInfoVo> queryCaseInfoTaskList(Page page, WorkTaskPoolCondition workTaskPoolCondition) {
        return baseMapper.queryCaseInfoTaskList(page, workTaskPoolCondition);
    }
    @Override
    public IPage<ApproveTaskVo> querySpecialPoolTaskList(Page page, WorkTaskPoolCondition workTaskPoolCondition) {
        return baseMapper.querySpecialPoolTaskList(page, workTaskPoolCondition);
    }

    @Override
    public Integer modifyStick(List<WaitTaskVO> waitTaskVOList, String status) {
        return baseMapper.modifyStick(waitTaskVOList, status);
    }

    @Override
    public Integer modifyLock(List waitTaskVOList, String status) {
        return baseMapper.modifyLock(waitTaskVOList, status);
    }

    @Override
    public WorkTaskPool findByApplyAndStageNo(String applyNo, String stageNo) {
        return this.getOne(Wrappers.<WorkTaskPool>query().lambda()
                .eq(StringUtils.isNotBlank(applyNo), WorkTaskPool::getApplyNo, applyNo)
                .eq(StringUtils.isNotBlank(stageNo), WorkTaskPool::getStageNo, stageNo));
    }

    @Override
    public JSONObject getRuleJSONObject(CaseContractInfo caseContractInfo) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("businessType",caseContractInfo.getBusinessType());
        return jsonObject;
    }

    @Override
    public List<String> queryNoOperateApproveTaskList(WorkTaskPoolCondition workTaskPoolCondition) {
        return baseMapper.queryNoOperateApproveTaskList(workTaskPoolCondition);
    }

    @Override
    public List<WorkTaskPool> getWorkTaskListByCondition(String applyNo,String scheduleId) {
        return workTaskPoolMapper.getWorkTaskListByCondition(applyNo,scheduleId);
    }

    @Override
    public WorkTaskPool getNextWorkTaskByCondition(String applyNo, String scheduleId, String approveStaff) {
        WorkTaskPool nextWorkTask = workTaskPoolMapper.getNextWorkTaskByCondition(applyNo,scheduleId,approveStaff);
        return nextWorkTask;
    }

    @Override
    public List<WorkTaskPool> listAllNormalFlowPool(String businessStateIn, String processType) {
        return baseMapper.listAllNormalFlowPool(businessStateIn,processType);
    }

}
